
/*******************************************************************************
File: Romerize Inflation
Purpose: Estimate different specifications of the aggregate Phillips Curve
Last Update: Dec 14, 2018
Last Update by: Juan Herreño
*******************************************************************************/




clear all
set more off
 set matsize 800
eststo clear
clear matrix

 
* Set the local name with your name.
local name = "juan"


* set your path under your name
if "`name'" == "juan" { 
cd "/Users/juanherreno/Dropbox/Investigacion/StateLevelCPIs/stata"
}

if  "`name'" == "emi" {
cd "c:/mydocs/dropbox/StateLevelCPIs/stata"
}

if  "`name'" == "joe" {
cd "/Users/joehazell/Dropbox/StateLevelCPIs/Stata/"
}

if  "`name'" == "jon" {
cd ""
}

if "`name'" == "juan_pc" { 
cd "C:/Users/jdh2181/Dropbox/Investigacion/StateLevelCPIs/stata/"
}


import excel "Code/code_to_share/data_romerize_inflation.xlsx", first clear sheet("Sheet1")  cellrange("A20")
keep CPIAUCSL CUSR0000SAH1 CUUR0000SEHA CUSR0000SEHC CUSR0000SA0L2 observation_date USSTHPIInflation CSUSHPINSA MORTGAGE30US CUSR0000SA0L12E CPILFESL
rename CPIAUCSL cpi
rename CUSR0000SAH1 shelter
rename CUUR0000SEHA rent
rename CUSR0000SEHC oer // owner_equivalent_rent
rename CUSR0000SA0L2 cpi_less_shelter
rename CUSR0000SA0L12E cpi_less_shelter_fe

gen year = year(dofd(observation_date))
gen month = month(dofd(observation_date))
drop observation_date
gen date_temp = ym(year,month)
format date_temp %tm
tsset date_temp


* Create inflation rates.
gen pi_cpi = cpi/l12.cpi - 1
gen pi_shelter = shelter/l12.shelter - 1
gen pi_rent = rent/l12.rent - 1
gen pi_oer = oer/l12.oer - 1
gen pi_cpi_less_shelter = cpi_less_shelter/l12.cpi_less_shelter - 1
gen pi_cpi_less_shelter_fe = cpi_less_shelter_fe/l12.cpi_less_shelter_fe - 1
gen pi_cpi_less_fe = CPILFESL/l12.CPILFESL - 1

* Create house price series that use the best data available at the time
rename CSUSHPINSA pi_caseshiller 
gen pi_mortgagerates = MORTGAGE30US/l12.MORTGAGE30US -1
gen pi_house_prices = pi_caseshiller if pi_caseshiller != .
replace pi_house_prices = USSTHPIInflation if pi_caseshiller == . & USSTHPIInflation !=.
replace pi_house_prices = pi_shelter if pi_caseshiller & USSTHPIInflation == .


gen pi_ignoring_oer = pi_cpi_less_shelter*(1-0.3209) + pi_rent*0.3209 // Ignoring OER. Use only rent to compute the shelter component
gen pi_owned_asset_pricing = 0.5*pi_house_prices + 0.5*pi_mortgagerates // Owned housing as an average of inflation rate of houses and mortgage rates
gen pi_shelter_asset_pricing = 0.8024*pi_owned_asset_pricing + (1-.8024)*pi_rent // 0.8024 = 0.22848/(0.22848 + 0.05624). 0.22848 is the weight of homeownership in the 1982 CPI. 0.05624 is the weight of rent.
gen pi_cpi_asset_pricing = 0.2918*pi_shelter_asset_pricing + (1-.2918)*pi_cpi_less_shelter // 0.2918 is the weight of shelter in the 1982 CPI.
gen pi_cpi_core_asset_pricing = (0.2918/0.7372)*pi_shelter_asset_pricing + ((0.7372 - 0.2918)/0.7372)*pi_cpi_less_shelter_fe // 0.7372 is the weight of Core CPI in the 1982 CPI.

drop if pi_cpi_asset_pricing == .
tsline pi_cpi_asset_pricing pi_cpi 
graph save "Graphs/Romerized_inflation", replace
